package com.gjh.study.mybatis.mapper2;

import com.gjh.study.mybatis.domain.Student;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * @author guangjh
 * @version 1.0
 * @date 2020/7/11 21:12
 */
public interface StudentMapper {
    @Select("select * from tb_student where clazz_id = #{id}")
    @Results({
            @Result(id = true, property = "id", column = "id"),
            @Result(property = "name", column = "name"),
            @Result(property = "sex", column = "sex"),
            @Result(property = "age", column = "age")
    })
    List<Student> selectStudentsByClazzId(Integer clazz_id);

    @Select("select * from tb_student where id = #{id}")
    @Results({
            @Result(id = true, property = "id", column = "id"),
            @Result(property = "name", column = "name"),
            @Result(property = "sex", column = "sex"),
            @Result(property = "age", column = "age"),
            @Result(property = "clazz", column = "clazz_id",
                    one = @One(select = "com.gjh.study.mybatis.mapper2.ClazzMapper.selectClazzById", fetchType = FetchType.EAGER))
    })
    Student selectStudentById(Integer id);
}
